## 创建并写入文件
with open("hello.txt","w") as file:
    file.write("你好\n")
    file.write("这里是北京！\n")
    print("文件创建并且写入成功：")

## 读取文件内容
with open('hello.txt','r') as file:
    content = file.read()
    print("hello.txt的文件内容如下：")
    print(content)

## 追加内容到文件中
with open('hello.txt','a') as file:
    file.write("我在美国很想你！")
    print("\n 文件已经追加至文件")

## 读取文件中所有行并逐行处理
with open('hello.txt','r') as file:
    lines = file.readlines()
    print("\n 文件中的每行内容如下：")
    for line in lines:
        print(line.strip()) ## strip() 去除末尾的换行符
